const schedule = require('node-schedule');
const path = require('path');

async function ScheduleAction(taskMes) {
        let executeSecond = taskMes.execute_second || '*';
        let executeMinute = taskMes.execute_minute || '*';
        let executeHour = taskMes.execute_hour || '*';
        let executeDay = taskMes.execute_day || '*';
        let executeMonth = taskMes.execute_month || '*';
        let executeYear = taskMes.execute_year || '*';
        let scheduleTime = `${executeSecond} ${executeMinute} ${executeHour} ${executeDay} ${executeMonth} ${executeYear}`;
        let taskName = taskMes.task_name;
        let schedule1 = schedule.scheduleJob(scheduleTime, function () {
            try {
                let actionPath = path.join(__dirname, `./actions/${taskName}`);
                require(actionPath)();
            } catch (e) {
                console.log(e);
            }
        });
}
module.exports = ScheduleAction;